#ifndef USER_H
#define USER_H

#include <QObject>
#include <QPointF>
#include <QVariant>
#include "serial.h"
#include "SerialEvent.h"

class user : public QObject
{
    Q_OBJECT
public:
    explicit user(QObject *parent = nullptr);
    ~user();

    serial* getSerialClass();
    SerialEvent* getSerialEventClass();
    void setOneStartID(int can, int index, QString data);
    QString getOneStartID(int can, int index);
    void setOneEndID(int can, int index, QString data);
    QString getOneEndID(int can, int index);
    void setOneEnableFlag(int can, int index, int flag);
    int getOneEnableFlag(int can, int index);
    void setOneResistanceFlag(int can, int flag);
    int getOneResistanceFlag(int can);

    Q_INVOKABLE void setMyProperty(QString property, QVariant value, int index = 0);
    Q_INVOKABLE QVariant getMyProperty(QString property, int index = 0);

    Q_INVOKABLE void beginSerialScan();
    Q_INVOKABLE void openSerialPort(QString port);
    Q_INVOKABLE void closeSerialPort();
    Q_INVOKABLE void sendSerialData(QString mode, int can, bool resistance, int index = 0);

    QByteArray createFilterSetting(QString mode, int can, bool resistance, int index);

    Q_INVOKABLE int hexToDec(QString hex);

    Q_INVOKABLE QPointF getCursorPos();

signals:
    void filterIDChanged(uchar index);
    void configProgressChanged(int current, int target);
public slots:

private:
    SerialEvent *mSerialEvent;
    serial *mSerial;
    QStringList m_startID1;
    QStringList m_endID1;
    QList<int> m_enableFlag1;
    QStringList m_startID2;
    QStringList m_endID2;
    QList<int> m_enableFlag2;
    int resistanceFlag[2] = {0};

};

#endif // USER_H
